package com.neu.controller;


import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageInfo;
import com.neu.common.Result;

import com.neu.entity.Admin;
import com.neu.entity.Audit;
import com.neu.entity.Hire;

import com.neu.entity.Params;

import com.neu.service.HireService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/hire")
public class HireController {
    @Autowired
    private HireService hireService;
//    @Autowired


    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Hire> info = hireService.findBySearch(params);
        return Result.success(info);
    }

    @PostMapping
    public Result add(@RequestBody Hire hire){


        //2.往预订表里插入一条预订记录
        hire.setTime(DateUtil.now());
        hire.setPay("Unpaid");
        hireService.add(hire);


        return Result.success();
    }

    @PostMapping("/audit")
    public Result audit(@RequestBody Hire hire){
        hireService.audit(hire);
        return Result.success();
    }

//    @GetMapping("/getTutorInformation")
//    public Result getTutorInformation(@RequestBody Hire hire){
//        Admin tutor = hireService.getTutorInformation(hire);
//        return Result.success(tutor);
//    }

    @PutMapping("/payment")
    public Result payment(@RequestBody Hire hire){
        hireService.payment(hire);
        return Result.success();
    }


    @PutMapping("/interact")
    public Result interact(@RequestBody Hire hire){
        hireService.interact(hire);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        hireService.delete(id);
        return Result.success();
    }
}
